//
//  GWVerisonTipsView.m
//  ShandsHotel
//
//  Created by zh_s on 2018/10/12.
//  Copyright © 2018年 zh_s. All rights reserved.
//https://github.com/JonyFang/FFPopup各个样式t弹窗 弹框

#import "GWVerisonTipsView.h"

@implementation GWVerisonTipsView

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
//        _title = title;
//        _infoStr = info;
//        _dic = dic;
        [self createUI];
    }
    return self;
}
- (instancetype)init {
    if (self = [super init]) {
        [self createUI];
    }
    return self;
}


- (void)createUI {
    UIView *backView = [[UIView alloc]init];
    backView.backgroundColor = [UIColor blackColor];
    backView.alpha = 0.5;
    backView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [self addSubview:backView];
    
    UIView *mainBackView = [[UIView alloc]init];
    mainBackView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    mainBackView.backgroundColor = [UIColor clearColor];
    [self addSubview:mainBackView];
    
    UILabel *infoLabel = [[UILabel alloc]init];
//    infoLabel.text = [YCUserData sharedManager].updataDescription;
//    infoLabel.text = [NSString stringWithFormat:@"%@",@"1、系统成绩；\n2、优化加载；\n3、增强体验;\n4、兼容iPhone X，iPhone XS，iPhone XS Max，iPhone XR等机型的布局，优化webview；\n5、修复部分bug，系带你的发现。"];
    infoLabel.font = FONT(14);
    infoLabel.numberOfLines = 0;
    infoLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [infoLabel sizeToFit];
    [mainBackView addSubview:infoLabel];
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(HEIGHT_CONSTARIN(4));
        make.width.mas_equalTo(WIDTH_CONSTARIN(240));
    }];
    
    UIView *mainView = [[UIView alloc]init];
    mainView.backgroundColor = [UIColor whiteColor];
//    mainView.layer.cornerRadius = HEIGHT_CONSTARIN(4);
//    mainView.clipsToBounds = YES;
    [mainBackView addSubview:mainView];
    mainView.backgroundColor = [UIColor clearColor];
    [mainView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
//        make.top.equalTo(infoLabel).offset(HEIGHT_CONSTARIN(-85));
        make.centerY.equalTo(self);
//        make.bottom.equalTo(infoLabel).offset(HEIGHT_CONSTARIN(70));
        make.height.mas_equalTo(230);
        make.width.mas_equalTo(217);
    }];
    
    UIImageView *backImg = [[UIImageView alloc]init];
    backImg.image = IMAGE_NAME(@"bg_text_alert");
    [mainView addSubview:backImg];
    mainView.userInteractionEnabled = YES;
    [backImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(mainView);
    }];
    
    UILabel *topLabel = [[UILabel alloc]init];
    topLabel.font = FONT(16);
    topLabel.textColor = MAIN_ACTIVE_COLOR;
    topLabel.text = @"参与内测\n需要消耗1NFT";
    topLabel.textAlignment = NSTextAlignmentCenter;
    topLabel.numberOfLines = 0;
    [mainView addSubview:topLabel];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainView).offset(WIDTH_CONSTARIN(15));
        make.right.equalTo(mainView).offset(WIDTH_CONSTARIN(-15));
        make.top.equalTo(mainView).offset(115);
//        make.height.mas_equalTo(50);
    }];
//
//    UILabel *titleLabel = [[UILabel alloc]init];
//    titleLabel.font = [UIFont boldSystemFontOfSize:[ToolsClass getFont:16]];
//    titleLabel.text = @"有新版本了！";
//    [mainView addSubview:titleLabel];
//    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(mainView).offset(WIDTH_CONSTARIN(25));
//        make.right.equalTo(mainView).offset(WIDTH_CONSTARIN(-25));
//        make.top.equalTo(mainView).offset(HEIGHT_CONSTARIN(55));
//        make.height.mas_equalTo(HEIGHT_CONSTARIN(18));
//    }];
    
//    NSArray *btnTitleArray = @[@"今日不再提醒",@"去更新"];
    NSString * leftTitle = @"";
//    if ([[YCUserData sharedManager].ifForcedUpdate integerValue] == 1) {
//        leftTitle = @"取消";
//
//    }else {
//        leftTitle = @"今日不再提醒";
//    }
    NSArray *btnTitleArray = @[@"立即参与",@"暂不参与"];
    for (NSInteger i = 0; i < btnTitleArray.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:btnTitleArray[i] forState:UIControlStateNormal];
        [button setTitleColor:i == 0?UIColor.whiteColor:MAIN_ACTIVE_COLOR forState:UIControlStateNormal];
        button.titleLabel.font = FONT(12);
        button.tag = 100 + i;
        [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [mainView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(16 + (84 +13) *i);
//            make.left.equalTo(mainView).offset(WIDTH_CONSTARIN(290/2.f)*i);
            make.bottom.mas_equalTo(mainView.mas_bottom).mas_offset(-14);
            make.height.mas_equalTo(33);
            make.width.mas_equalTo(84);
        }];
        if (i == 0) {
            button.backgroundColor = MAIN_BACKCOLOR;
        }else {
            button.backgroundColor = UIColor.clearColor;
            button.layer.borderColor = MAIN_ACTIVE_COLOR.CGColor;
            button.layer.borderWidth = 0.5f;
        }
        GWRadius(button, 16);
    }
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.fromValue = @(0.2);
    animation.toValue = @(1.f);
    animation.duration = 0.25;
    [mainBackView.layer addAnimation:animation forKey:nil];
    
    [mainBackView bringSubviewToFront:infoLabel];
}

- (void)btnClick:(UIButton *)sender {
    if (sender.tag == 100) {
        
//        if ([[YCUserData sharedManager].ifForcedUpdate integerValue] == 1) {
//            SHOW_TOP_TIPS(@"必须升级新版本，app才能正常使用！", 0);
//            return;
//        }else {
//            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
//            [formatter setDateFormat:@"yyyy-MM-dd"];
//            NSString *loginTipsTime = [formatter stringFromDate:[NSDate date]];
//            [GWUserDefaults setObject:loginTipsTime forKey:@"loginTipsTime"];
//            [GWUserDefaults synchronize];
//
//        }
        
        
    }
    self.block(sender.tag);
}


@end
